package fristphase.day9_13;

public class MyRewrite {
    public static void main(String[] args) {
        Point point = new Point(100,200);
        Point point1 = new Point(100,200);
        String str = new String("hello");
        String str1 = new String("hello");
        StringBuilder builder = new StringBuilder("hello");
        StringBuilder builder1 = new StringBuilder("hello");

        System.out.println(point);//默认调用toString方法
        System.out.println(point.toString());
        System.out.println(point.equals(point1));//true

        System.out.println(str.equals(str1));//默认重写了equals方法true
        System.out.println(str == str1);//false

        System.out.println(builder.equals(builder1));//没有重写
        System.out.println(str.equals(builder));//str与builder不是同一个类，直接判错。
    }
}
class Point{
    private int x,y;
    Point(int x,int y){
        this.x = x;
        this.y = y;
    }

    public String toString(){
        return "Point{"+"x="+x+"y="+y+"}";
    }

    public boolean equals(Object obj){
        if(this == obj)return true;
        if(obj == null || getClass() != obj.getClass())return false;
        Point point = (Point) obj;
        return  x == point.x && y == point.y;
    }

    public void setX(int x){
        this.x = x;
    }

    public int getY(){
        return y;
    }
}
